package ks.client.controllers;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import ks.client.UserContext;
import ks.client.controllers.commands.LeaveCommandController;
import ks.client.gui.GMGUI;
import ks.client.gui.UMGUI3;
import ks.client.ipc.Client;
import ks.client.kommander.Action;
import ks.client.kommander.Kommander;
import ks.client.lobby.Lobby;
import ks.client.parser.CommandParser;
import ks.framework.common.Message;
import ks.managers.table.Table;
import ks.managers.table.TableManager;

import org.w3c.dom.Document;

/**
 * Attempt to process keyboard commands from the lobby text field.
 * 
 * @author George Heineman
 * @author szutshi
 */
public class LeaveTableClick implements ActionListener {
	
	/** Context governing communication. */
	Lobby lobby;
	UserContext context;
	int num;
	
	/**
	 * The Table Input processor needs to know the UserContext to complete
	 * its tasks.
	 * 
	 * @param context
	 */
	public LeaveTableClick (Lobby lobby, UserContext context, int num) {
		this.lobby = lobby;
		this.context = context;
		this.num = num;
	}
	
	/**
	 * Process string entered by user.
	 *  
	 * @param s
	 */
	public void actionPerformed(ActionEvent e) {
		new LeaveCommandController(lobby).send(num, new Action() {

			@Override
			public void ack() {
				GMGUI gui = lobby.getGMGUI();
				String me = context.getUser();
				TableManager tm = context.getTableManager();
				Table t = tm.getTable(num);
				t.removePlayer(me);
				
				gui.setVisible(false);
				gui.dispose();
				gui.updateUserList();
			}	
			public void nack() {}
		});
	}
}
	


